package com.sgl.blog.controller.user;

import com.sgl.blog.pojo.BlogAccount;
import com.sgl.blog.service.AccountService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * 简介
 * 作者： 李志伟
 * 日期： 2020/4/11
 * 时间： 13:24
 */
@Controller
@RequestMapping("user")
public class CenterController {


    @Resource
    private AccountService accountService;


    @PostMapping("update")
    public String info(BlogAccount account, Model model, HttpSession session) {

        BlogAccount blogAccount = (BlogAccount) session.getAttribute("account");

        blogAccount.setAccountNickname(account.getAccountNickname());
        blogAccount.setAccountBirthday(account.getAccountBirthday());
        blogAccount.setAccountGender(account.getAccountGender());
        blogAccount.setAccountAge(account.getAccountAge());

        if (accountService.updateAccount(blogAccount)) {
            model.addAttribute("msg", 7);
            session.setAttribute("account", blogAccount);
        }

        return "user/info";
    }
}
